package com.example.booksactivity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.booksactivity.Bean.Book;
import com.example.booksactivity.R;

import java.util.List;

public class BookAdapter extends ArrayAdapter<Book> {
    int resourceid;
    public BookAdapter(@NonNull Context context, int resource, @NonNull List<Book> objects) {
        super(context, resource, objects);
        this.resourceid=resource;

    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        View view=convertView;
        if (view==null){
            view= LayoutInflater.from(getContext()).inflate(resourceid,null);

        }
        ImageView bookimg=view.findViewById(R.id.bookimg);
        TextView bookname=view.findViewById(R.id.bookname);
        TextView authorname=view.findViewById(R.id.authorname);
        Book b=getItem(position);
        bookimg.setImageResource(b.getBookimg());
        bookname.setText(b.getBookname());
        authorname.setText("作者："+b.getAuthorname());
        return view;
    }
}
